package com.zhangxiaofanfan.hotcode.first;

/**
 *
 * @date 2024-07-13 03:14:13
 * @author zhangxiaofanfan
 */
public class HotCode078 {
    public static void main(String[] args) {
        HotCode078 hotCode = new HotCode078();
        int[] nums = {3,2,1,0,4};
        System.out.println(hotCode.canJump(nums));
    }

    public boolean canJump(int[] nums) {
        int maxJumpIndex = 0, curIndex = 0;
        while (maxJumpIndex >= curIndex) {
            if (maxJumpIndex >= nums.length - 1) {
                return true;
            }
            maxJumpIndex = Math.max(maxJumpIndex, curIndex + nums[curIndex]);
            curIndex++;
        }
        return false;
    }
}
